package edu.bu.cs673.superkids123.common.controller;

import edu.bu.cs673.superkids123.AbstractController;
import edu.bu.cs673.superkids123.AbstractFrame;
import edu.bu.cs673.superkids123.common.DataObjectAccess.ParentManager;
import edu.bu.cs673.superkids123.common.controller.exceptions.AuthException;
import edu.bu.cs673.superkids123.common.controller.exceptions.PlayedTooLongException;
import edu.bu.cs673.superkids123.common.model.Parent;
import edu.bu.cs673.superkids123.parents.view.ParentSettingsView;

public class ParentsLoginController extends AbstractController {

	public ParentsLoginController(AbstractFrame mainFrame) {
		super(mainFrame);
	}

	public void login(String userName, String password) throws AuthException {
		Parent parent = ParentManager.getParentByUsernameAndPassword(
				userName, password);
		if (parent != null) {
			try {
				authController.login(parent);
			} catch (PlayedTooLongException e) {
				// Ignore because parents can't play too long
			}
			getMainFrame().changeView(ParentSettingsView.class);
		} else {
			throw new AuthException();
		}
		;
	}
}
